﻿package ui;

import java.rmi.RemoteException;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;

import vo.salesManager.CustomerAddPanelVO;

import main.Main;

import components.MyButton;
import components.MyFrame;
import components.MyPanel;

public class CustomerAddPanel extends MyPanel{

	
	private MyButton logoutButton;
	private MyButton returnbackButton;
	
	private JScrollPane addcustomerpanelScrollPane;
	private JLabel pleaseaddcustomerLabel;
	private JLabel usernameaddLabel;
	private JTextField usernameaddField;
	private JLabel passwordaddLabel;
	private JPasswordField passwordaddField;
	private MyButton confirmaddcustomerButton;

	@Override
	protected void initComponent() {
		logoutButton = new MyButton("注销");
		returnbackButton = new MyButton("返回");
		logoutButton.setBounds(MyFrame.WIDTH-80,0, 80, 20);
		returnbackButton.setBounds(MyFrame.WIDTH-160,0, 80, 20);
		this.add(logoutButton);
		this.add(returnbackButton);
		addcustomerpanelScrollPane = new JScrollPane(this);
		addcustomerpanelScrollPane.setBounds(300, 150, 500, 450);
		addcustomerpanelScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
		pleaseaddcustomerLabel = new JLabel("请填写以下信息:");
		usernameaddLabel = new JLabel("用户名:");
		usernameaddField = new JTextField();
		passwordaddLabel = new JLabel("密码:");
		passwordaddField = new JPasswordField();
	    confirmaddcustomerButton = new MyButton("添加");
	    pleaseaddcustomerLabel.setBounds(10, 20, 120, 20);
	    usernameaddLabel.setBounds(20, 60, 80, 20);
	    usernameaddField.setBounds(100, 60, 150, 25);
	    passwordaddLabel.setBounds(20, 100, 80, 20);
	    passwordaddField.setBounds(100, 100, 150, 25);
	    confirmaddcustomerButton.setBounds(350, 140, 100, 40);
	    add(pleaseaddcustomerLabel);
	    add(usernameaddLabel);
	    add(usernameaddField);
	    add(passwordaddLabel);
	    add(passwordaddField);
	    add(confirmaddcustomerButton);
	    
	    logoutButton.setButtonAction("logout");
		returnbackButton.setButtonAction("toCustomerQuery");
		confirmaddcustomerButton.setButtonAction("addCustomer");
	}

	@Override
	protected void updateVO() {
		CustomerAddPanelVO capvo = null;
		try {
			capvo = Main.getLogic().getCapvo();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		capvo.setPassword(passwordaddField.getText());
		capvo.setUsername(usernameaddField.getText());
		try {
			Main.getLogic().setCapvo(capvo);
		} catch (RemoteException e) {
			e.printStackTrace();
		}
	}

}
